import DataStorage from '@/framework/infra/storage/DataStorage'

export default class CachedDataStorage extends DataStorage {
  #cached = {}

  setItem(key, value) {
    super.setItem(key, value)
    this.#cached[key] = value
  }

  getItem(key) {
    if (!(key in this.#cached)) {
      this.#cached[key] = super.getItem(key)
    }
    return this.#cached[key]
  }

  removeItem(key) {
    delete this.#cached[key]
    super.removeItem(key)
  }

  clear() {
    this.#cached = {}
    super.clear()
  }
}
